package model.element;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.JLayeredPane;

import model.Element;

public class Road extends Building {
	public static final int ROAD_SIZE = 20;
	
	/* --- */
	private ArrayList<Road> nearbyRoads = new ArrayList<Road>();
	
	/* Basic constructor.
	 * ~ the factory takes care of adding nearby roads. 
	 * ~ use the factory to create roads in the game. */
	public Road(int x, int y, int width, int height) {
		super(x, y, width, height);
	}
	public Road(int x, int y){
		this(x, y, ROAD_SIZE, ROAD_SIZE);
	}

	@Override
	public void tick() {
		// TODO Auto-generated method stub
	}
	
	public Dimension getGridLocation(){
		return this.getGridLocation(this.getWidth(), this.getHeight());
	} 

	public ArrayList<Road> getNearbyRoads() {
		return nearbyRoads;
	}

	public void setNearbyRoads(ArrayList<Road> nearbyRoads) {
		this.nearbyRoads = nearbyRoads;
	}

	public void print(){
		System.out.println(getX()+" ## "+getY());
		for(Road r : nearbyRoads){
			System.out.println(r.getX()+" "+r.getY());
		}
	}
	
	@Override
	public void kill() {
		for(Road r : nearbyRoads){
			r.nearbyRoads.remove(this);
		}
		super.kill();
	}
	
	public Color getColor(){
		return Color.GRAY;
	}
	
	@Override
	public int depth() {
		return JLayeredPane.DRAG_LAYER;
	}
	
	public String toString(){
		return "Road: "+rectangle;
	}
}
